﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Security.Principal;

using AKMII.DMRA.Business.Management;
using AKMII.DMRA.Common;

namespace AKMII.DMRA.Web
{
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            Constants.LogConfigFile = Server.MapPath(ConfigurationSettings.AppSettings["logging.config"]);
            Constants.ExcelReportPath = ConfigurationSettings.AppSettings["ReportPath"];

            LeadManager leadManager = new LeadManager();
            Application["City"] = leadManager.GetCity();
            Application["County"] = leadManager.GetCounty();
            //Application["Territory"] = leadManager.GetTerritory();
            Application["State"] = leadManager.GetState();
        }

        protected void Session_Start(object sender, EventArgs e)
        {
    
        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
            if (context.Request.IsAuthenticated == true)
            {
                FormsIdentity identity = (FormsIdentity)context.User.Identity;
                FormsAuthenticationTicket ticket = identity.Ticket;
                string[] roles = ticket.UserData.Split(',');
                context.User = new GenericPrincipal(identity, roles);
            }
        }

        protected void Application_Error(object sender, EventArgs e)
        {
            //Response.Redirect(@"~\Error.aspx");
        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }
    }
}